package com.mxfcode.front.bbs_login.mapper;

import com.mxfcode.entity.TSLoginTicket;
import org.apache.ibatis.annotations.*;

/**
 * @author moxiufeng
 * @date 2021/2/17 12:55
 */
@Mapper
public interface LoginTicketMapper {

    @SelectKey(keyProperty = "loginTicket.id", resultType = String.class, before = true,
            statement = "select replace(uuid(), '-', '')")
    @Options(keyProperty = "loginTicket.id", useGeneratedKeys = true)
    @Insert({
            "insert into t_s_login_ticket(id,user_id,ticket,status,expired) ",
            "values(#{loginTicket.id},#{loginTicket.userId},#{loginTicket.ticket},#{loginTicket.status},#{loginTicket.expired})"
    })
    int insertLoginTicket(@Param("loginTicket") TSLoginTicket loginTicket);

    @Select({
            "select id,user_id as userId,ticket,status,expired ",
            "from t_s_login_ticket where ticket=#{ticket}"
    })
    TSLoginTicket selectByTicket(@Param("ticket") String ticket);

    @Update({
            "<script>",
            "update t_s_login_ticket set status=#{status} where ticket=#{ticket} ",
            "<if test=\"ticket!=null\"> ",
            "and 1=1 ",
            "</if>",
            "</script>"
    })
    int updateStatus(@Param("ticket") String ticket, @Param("status") int status);

}
